But the value of the state variable will be one , how it will read the upcoming characters?
why do you think state variable value will interfere with reading character?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler